clear
clc

N = 1000;
f = 50;
w = 2*pi*f;
t = linspace(0,5/50,N);
theta = w*t;

% a b c coordinates
a = sin(theta);
b = sin(theta-2*pi/3);
c = sin(theta+2*pi/3);
abc = [a ; b ; c];

% Clarke transform (abc to alphabeta)
T_c = [2/3 -1/3 -1/3;0 1/sqrt(3) -1/sqrt(3)];
alphabeta = T_c*abc;
alpha = alphabeta(1,:);
beta  = alphabeta(2,:);

%Park transform (alphabeta to dq)
d =  alpha.*cos(theta) + beta.*sin(theta);
q = -alpha.*sin(theta) + beta.*cos(theta);
dq = [d;q];

figure(1)
subplot(311)
plot(t,abc)
legend('a','b','c')
subplot(312)
plot(t,alphabeta)
legend('alpha','beta')
subplot(313)
plot(t,dq)
legend('d','q')

clear
clc
N = 1000;
f = 50;
w = 2*pi*f;
t = linspace(0,5/50,N);
theta = w*t;

d = 1*ones(1,N);
q = 0*ones(1,N);
dq = [d;q];

alpha = cos(theta).*d - sin(theta).*q;
beta = sin(theta).*d + cos(theta).*q;
alphabeta = [alpha;beta];

d_ =  alpha.*cos(theta) + beta.*sin(theta);
q_ = -alpha.*sin(theta) + beta.*cos(theta);
dq_ = [d_;q_];

figure(2)
subplot(311)
plot(t,dq_)
legend('d','q')
subplot(312)
plot(t,alphabeta)
legend('alpha','beta')
subplot(313)
plot(t,dq)
legend('d','q')